package com.sky.validation.controller;

import com.alibaba.fastjson.JSONObject;
import com.sky.validation.dto.SchoolDto;
import com.sky.validation.dto.UserDto;
import com.sky.validation.service.IValidationService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.validation.Valid;

@Controller
public class ValidationController {

    @Resource
    private IValidationService validationService;

    @PostMapping("/test")
    @ResponseBody
    public Object testValidation(@RequestBody @Valid UserDto user) {
        return user;
    }

    @PostMapping("/school")
    @ResponseBody
    public Object school(@RequestBody @Valid SchoolDto school) {
        return school;
    }

    @PostMapping("/param")
    @ResponseBody
    public Object service(@RequestBody String param) {
        SchoolDto json = JSONObject.parseObject(param, SchoolDto.class);
        return validationService.test(json);
    }
}
